package com.lagou.edu.service.impl;

import com.lagou.edu.pojo.User;
import com.lagou.edu.dao.UserDao;
import com.lagou.edu.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("loginService")
public class LoginServiceImpl implements LoginService {

    @Autowired
    UserDao userDao;

    @Override
    public User queryUser(User user) {
        Example<User> userExample = Example.of(user);
        List<User> all = userDao.findAll(userExample);
        User us = all.size() > 1 ?  all.get(0) : null;
        return us ;

    }

    @Override
    public void insertUser(User user) {
        userDao.save(user);
    }

    @Override
    public void saveToken(User user) {
        userDao.saveAndFlush(user);
    }
}
